Getting a Google Maps API key
Description
Features such as maps and geocoding are built on services provided by Google. A Google API key is required to use these features in your Alpha Anywhere applications.
Discussion
The Map control and geocoding functions require API key to use it in a application. If no API key is supplied, you may see an error message in place of a map, in a popup message, or in the console log. If this happens, you need to create and add an APK key to your application for the Google API that is required to use the feature.
How to get an API key from Google
An API key can be created using the Google Cloud console. If you do not have a Google account, you will need to create one to get an API key.
Once logged into the Google Cloud console, you will first need to create a Project if you do not already have a Project. Once you've created the project, you can navigate to the APIs & Services dashboard to create an API key:
In the Library section, locate the Google Maps API you'd like to enable. The following APIs are used with Alpha Anywhere:
- API
- Description
- Maps JavaScript API
Required for most Google Maps operations, such as displaying a map, plotting markers on a map, or using Google Address auto-complete.
- Geocoding API
Required for translating an Address (123 N Main St, Springfield, MA) into latitude and longitude coordinates or calling the geocode_address() Xbasic function.
- Maps Static API
Required for generating and embedding a static map in an app.
Click the Enable button to add the API to your project.
Next, navigate to Credentials. Then, click Create Credentials and select API key from the dropdown.
Copy the API key. This API key can be entered in Alpha Anywhere in the Project Properties or Map control properties to enable access to the Google Maps API.
Keep your API key private.
Restricting API key Access
It's recommended to restrict what applications (or sites) can use your API key and what APIs someone can access using the API key. You can do this by editing the API key in the Credentials section. Access restrictions can be modified at any time.
To restrict the API key to specific sites or applications (e.g. Android or iOS applications), locate the Application restrictions section and select the type of application that will use your API key. Enter the required URL(s), IP Address(es), Android app, or iOS app information for the chosen application.
You can create multiple API keys if you have multiple applications that will require access.
To restrict the API key to specific Google APIs, locate the API restrictions section and select Restrict key. Select the APIs from the dropdown box that you'd like to include.
When you are finished updating restrictions, click Save to save your changes.
Entering an API key
Once have an API key, you can enter it in Project Properties.
Add the key to the corresponding Google API key property.
- Property
- Corresponding API
- Google Maps API key
Maps JavaScript API
- Google Static Maps API Key
Maps Static API
- Google Geocoding API Key
Geocoding API
Alternatively, your API key can be added to your project as a file stored in the Alpha Anywhere installation folder. Storing the key in your installation folder reduces the risk of accidentally exposing your API credentials in projects stored in public GitHub repositories (or other public source control solutions.)
- File Name
- Description
- GoogleMapsAPIKey.txt
Maps JavaScript API key. Will be used if the Google Maps API key property is blank.
- GoogleStaticMapsAPIKey.txt
Maps Static API key. Will be used if the Google Static Maps API Key property is blank.
- GoogleGeoCodingAPIKey.txt
Geocoding API key. Will be used if the Google Geocoding API Key property is blank.
If Alpha Anywhere is installed in the "Program Files (x86)" folder, you will need Administrator privileges in order to create the API file(s).